package main

import (
	"fmt"
	"time"
)

func main() {

	// ch1是一个正常的channel，不是单向的
	var ch1 = make(chan string, 5)

	// ch2是单向channel，只用于写float64数据
	var ch2 chan<- string = ch1

	// ch3是单向channel，只用于读取int数据
	var ch3 <-chan string = ch1

	go func() {

		for i := 1; i <= 10; i++ {

			go consumer(ch3)

			time.Sleep(time.Second * 3)
		}

	}()

	for i := 1; i <= 10; i++ {

		go producer(ch2, i)



	}

	for ; ; {

	}

}

func producer(channel chan<- string, i int) {

	channel <- fmt.Sprintf("%s::: %d", "辣子鸡", i)

	fmt.Println("生产商品", "辣子鸡:", i)



}

func consumer(channel <-chan string) {

	str := <-channel

	fmt.Println("购买商品", str)
}
